package com.voicechat.firstmet.activity;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.voicechat.firstmet.R;
import com.voicechat.firstmet.adapter.PostPictureAdapter;
import com.voicechat.firstmet.base.BaseActivity;
import com.voicechat.firstmet.bean.MySelfInfoBean;
import com.voicechat.firstmet.utils.ParcelableUtils;
import com.voicechat.firstmet.utils.PhoneUtils;
import com.voicechat.firstmet.utils.SPUtils;
import com.voicechat.firstmet.utils.StatusBarUtils;
import com.voicechat.firstmet.utils.Utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @ProjectName: FirstMet
 * @Package: com.voicechat.firstmet.activity
 * @ClassName: SharePhotoLookActivity
 * @Description: 查看共享秀照详情
 * @Author: ljp
 * @CreateDate: 2019/1/16 11:51
 * @Version: 1.0
 */
public class SharePhotoLookActivity extends BaseActivity {
    @BindView(R.id.linear_back)
    LinearLayout linearBack;
    @BindView(R.id.recycler_photo_album)
    RecyclerView recyclerPhotoAlbum;
    @BindView(R.id.smart_refresh)
    SmartRefreshLayout smartRefresh;
    @BindView(R.id.tv_photo_time)
    TextView tvPhotoTime;
    private String imagerUrl;
    private String time;
    private String id;
    private String TAG = "SharePhotoLookActivity";
    private MySelfInfoBean.ObjectBean mySeleInfo;
    private String token;
    private String deviceInfo;
    @Override
    protected int setStatusBarColor() {
        return 0;
    }

    @Override
    protected boolean isSettingStatusBarText() {
        return false;
    }

    @Override
    protected int loadLayout() {
        return R.layout.activity_share_photo_look;
    }

    @Override
    protected void initLayout(Bundle savedInstanceState) {
        ButterKnife.bind(this);
        //透明状态栏
        StatusBarUtils.Full(this);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }
        mySeleInfo = MySelfInfoBean.ObjectBean.CREATOR.createFromParcel(ParcelableUtils.unmarshall(
                SPUtils.getEditoString(SPUtils.SP_MYSELFINFO)));
        token = SPUtils.getEditoString(SPUtils.SP_TOKEN);
        deviceInfo = PhoneUtils.getDeviceInfo(context);
        imagerUrl = getIntent().getStringExtra("imageUrl");
        time = getIntent().getStringExtra("time");//创建时间
        id = getIntent().getStringExtra("id");//相册id
        initView();
        //更新浏览量
       // initHttp();

    }


    private void initView() {
        tvPhotoTime.setText(time);
        List<String> listImages = Arrays.asList(Utils.spitPictureUrl(imagerUrl));
        PostPictureAdapter pictureAdapter = new PostPictureAdapter(context, listImages, R.layout.item_post_picture);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 3);
        recyclerPhotoAlbum.setHasFixedSize(true);
        recyclerPhotoAlbum.setLayoutManager(gridLayoutManager);
        recyclerPhotoAlbum.setAdapter(pictureAdapter);
        pictureAdapter.setOnClick(new PostPictureAdapter.OnClick() {
            @Override
            public void onSetPictureClick(View view, int position) {
                ArrayList<String> stringArrayList = new ArrayList<>(listImages);
                Intent intent = new Intent(context, PictureViewerActivity.class);
                Bundle bundle = new Bundle();
                bundle.putStringArrayList("tlist", (ArrayList<String>) stringArrayList);
                intent.putExtra("position", position);
                intent.putExtra("list", bundle);
                context.startActivity(intent);
            }
        });
    }

    @OnClick(R.id.linear_back)
    public void onClick() {
        finish();
    }
}
